<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品库存明细列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="col-xs-3">
                                <label>[[#{warehouse}]]：</label>
                                <div class="input-group">
                                    <input name="warehouseId" class="form-control" type="hidden">
                                    <input id="suggest-warehouse" class="form-control" type="text">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <label>[[#{sku}]]：</label>
                                <input type="text" name="productCode"/>
                            </li>
                            <li>
                                <label>[[#{orderNo}]]：</label>
                                <input type="text" name="orderNo"/>
                            </li>
                            <li>
                                <label>[[#{warehousePosition}]]：</label>
                                <input type="text" name="warehousePosition"/>
                            </li>
                            <li>
                                <label>[[#{createTime}]]：</label>
                                <input type="text" class="time-input" id="beginCreateTime" th:placeholder="#{beginTime}" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endCreateTime" th:placeholder="#{endTime}" name="params[endCreateTime]" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;[[#{search}]]</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;[[#{reset}]]</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="inventory:details:export">
                    <i class="fa fa-download"></i> [[#{export}]]
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-suggest-js" />
    <script th:inline="javascript">
        var removeFlag = [[${@permission.hasPermi('inventory:details:remove')}]];
        var prefix = ctx + "business/inventory/details";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: i18n('commodityInventoryDetails'),
                columns: [{
                    checkbox: true
                },
                {
                    field: 'detailsId',
                    title: '商品库存id',
                    visible: false
                },
                {
                    field: 'warehouseName',
                    title: i18n('warehouseName')
                },
                {
                    field: 'productName',
                    title: i18n('productName')
                },
                {
                    field: 'productCode',
                    title: i18n('sku')
                },
                {
                    field: 'styleCode',
                    title: i18n('spu')
                },
                {
                    field: 'spec',
                    title: i18n('spec')
                },
                {
                    field: 'orderNo',
                    title: i18n('orderNo')
                },
                {
                    field: 'warehousePosition',
                    title: i18n('warehousePosition')
                },
                {
                    field: 'changeQuantity',
                    title: i18n('changeQuantity')
                },
                {
                    field: 'quantity',
                    title: i18n('quantity')
                },
                {
                    field: 'type',
                    title: i18n('type'),
                    formatter: function(value, row, index) {
                        if(value == 1){
                            return i18n('inBound');//"入库"
                        } else if(value == 2){
                            return i18n('outbound');//"出库"
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'remark',
                    title: i18n('remark')
                },
                {
                    field: 'createBy',
                    title: i18n('createBy')
                },
                {
                    field: 'createTime',
                    title: i18n('createTime')
                }]
            };
            $.table.init(options);
        });

        var warehouseSuggest = $("#suggest-warehouse").bsSuggest({
            url: ctx + "business/warehouse/select/list",
            idField: "warehouseId",
            keyField: "warehouseName",
            clearable: true,
            ignorecase: true,
            hideOnSelect: true,
            effectiveFields: ["warehouseId", "warehouseName"],
            effectiveFieldsAlias: {warehouseId: "仓库ID", warehouseName: "仓库"},
        }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
            console.log('onSetSelectValue: ', selectedData);

            $("input[name='warehouseId']").val(selectedRawData.warehouseId);
        }).on('onUnsetSelectValue', function (e) {
            //console.log("onUnsetSelectValue=="+e);
            $("input[name='warehouseId']").val("");
        });
    </script>
     <script th:inline="javascript">
         var ROOT = [[${#servletContext.contextPath}]];
         var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

         //初始化i18n
         $.i18n.properties({
             path: ROOT + '/i18n/',//这里表示访问路径
             name: 'messages',//文件名开头
             language: LANG_COUNTRY,//文件名语言 例如en_US
             mode: 'map'//默认值
         });

         //i18n函数
         function i18n(msgKey) {
             try {
                 return $.i18n.prop(msgKey);
             } catch (e) {
                 return msgKey;
             }
         }
     </script>
</body>
</html>